<?php

/**
 * System's functions file
 *
 * @author coder_
 */

/**
 * Function that prints given text and goes to next line
 *
 * @param $text
 * @return void
 */
function println($text)
{
    print($text . '<br/>');
}

/**
 * Function that prints current time in microseconds
 *
 * @return void
 */
function ptime()
{
    println(microtime(true));
}

/**
 * Function that prints system start time in microseconds
 *
 * @return void
 */
function pstart_time()
{
    println(START_TIME);
}

/**
 * Function that prints given variable dump
 *
 * @param $var
 * @param bool $stop
 * @return void
 */
function dump($var, $stop = true)
{
    print('<pre>');
    var_dump($var);
    if ($stop) die;
}

/**
 * Function that returns module manager object
 *
 * @return object
 */
function getModules()
{
    return _ModuleManager::getInstance();
}

/**
 * Function that returns module with given name
 *
 * @param $name
 * @return object
 */
function getModule($name)
{
    return _ModuleManager::getInstance()->{$name};
}


/**
 * Function that prints total execution time
 *
 * @return void
 */
function pexec_time()
{
    println('');
    println(microtime(true) - START_TIME);
}

/**
 * Function that checks if current request is ajax request
 *
 * @return bool
 */
function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
        ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

/**
 *
 *
 * @param $array
 * @return bool
 */
function isAssoc($array)
{
    return !is_numeric(implode('', array_keys($array)));
}

function getLang($lang)
{
    $uri = getModule('Url')->getUri();
    return URL . '/' . $lang . $uri;
}

function lang($lang)
{
    echo getLang($lang);
}

function __($label = null, $fallback = '')
{
    if(is_null($label)) return;

    $string = getModule('Translations')->getTranslation($label);
    echo $string ? $string : $fallback;
}